package com.bjsxt.livegoods.banner.service.service.impl;

import com.bjsxt.livegoods.banner.service.service.BannerService;
import com.bjsxt.livegoods.dao.banner.BannerDao;
import com.bjsxt.livegoods.entity.Banner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 轮播图服务类型  ---服务类型
 */
@Service
public class BannerServerImpl implements BannerService {

    /**
     * 结果格式是：{'status':200,'result':{"","",""}}
     */
    @Autowired
    private BannerDao bannerDao;

    @Override
    public Map<String, Object> getBanners() {
        //访问数据库Monogodb,查询Banners
        List<Banner> banners = this.bannerDao.findBanners();
        //结果对象的创建
        Map<String,Object> result=new HashMap<>();
        //返回结果的状态码
        result.put("status",200);
        //整理轮播图地址集合
        List<String> results=new ArrayList<>();
        for(Banner banner:banners){
            //把Banner对象的图片的地址维护在一个集合中
            results.add(banner.getImg());
        }
        result.put("results",results);
        return result;
    }
}
